package com.teacher.hong.controller;

import com.teacher.hong.entity.Clazz;
import com.teacher.hong.service.IClazzService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 班级类控制器
 */
@RestController
@RequestMapping("clazz")
public class ClazzController extends BaseController {

    @Resource
    IClazzService clazzService;

    /**
     * 获取班级列表
     * @return
     */
    @GetMapping
    public Object index() {
        List<Clazz> clazzes = clazzService.list();
        return success("success", clazzes);
    }

    /**
     * 新增/编辑
     * @return
     */
    @PostMapping("edit")
    public Object edit(@RequestBody Clazz clazz) {
        return clazzService.save(clazz) ?
                success("success", null) :
                fail("fail, clazzName is exists.", 402);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @PostMapping("delete")
    public Object delete(@RequestParam Integer id) {
        return clazzService.remove(id) ?
                success("success", null) :
                fail("fail, id is not exists.", 402);
    }

}
